This repository was archived by the owner on Jan 13, 2025. It is now read-only.
added optional log functionality#65
Open
andres-fr wants to merge 2 commits intoElsevierDev:masterfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a proposed PR to fix issue #26 (disabling logging).
Since a new logger is being created for several files when the lib is loaded, it is already late/cumbersome for the user to keep track of the internals and modify the logging behaviour. This proposed fix addresses this issue as follows:
Loggers are singletons inside the
log_utilnamespace. This way we can keep track of all loggers in a centralized way. This is implemented bya) using a dictionary to keep all logs
b) making the log creator a protected function and
c) the log getter tries to fetch an existing singleton, and otherwise creates+returns one if it didn't exist
The module incorporates a
log_to_directoryfunction that provides the desired functionality to the specified loggers (or to all if none specified). I.e. default behaviour is not logging, and users can opt-in at any time and also provide their desired destiny. This function has been added to__init__in order to keep it more accessible to users.The user simply has to add the following lines anywhere inside their application code:
I think this is an improvement for the following reasons:
Note that the use of a singleton is the least intrusive fix given that several modules are creating loggers as side effect when loaded.
Let me know what you think! Hope this helps.
Cheers,
Andres